﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Minestorm;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Minestorm.Retro.Screens;

namespace Minestorm.Screens
{
    public class GameTypeScreen : GameScreen
    {
        ContentManager content;
        Texture2D backgroundTexture;

        public GameTypeScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }

        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            backgroundTexture = content.Load<Texture2D>("Screens\\gametype");
        }

        public override void UnloadContent()
        {
            content.Unload();
        }

        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            if (input.IsNewKeyPress(Keys.Enter, null, out playerIndex) || input.IsNewButtonPress(Buttons.A, null, out playerIndex))
            {
                ExitScreen();
                ScreenManager.AddScreen(new GameplayScreen(), playerIndex);
            }

            if (input.IsNewKeyPress(Keys.Escape, null, out playerIndex) || input.IsNewButtonPress(Buttons.B, null, out playerIndex))
            {
                ExitScreen();
                ScreenManager.AddScreen(new MainMenuScreen(), playerIndex);
            }
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);

            spriteBatch.Begin();

            spriteBatch.Draw(backgroundTexture, fullscreen,
                             new Color(TransitionAlpha, TransitionAlpha, TransitionAlpha));

            spriteBatch.End();
        }
    }
}
